// import 'package:euromillions/Checker/EJ_CheckerPageVC.dart';
// import 'package:euromillions/Generator/EJ_GeneratorPageVC.dart';
// import 'package:euromillions/Home/EJ_HomePageVC.dart';
// import 'package:euromillions/Results/EJ_ResultPageVC.dart';
// import 'package:euromillions/Statistics/EJ_StatisticsPageVC.dart';
// import 'package:euromillions/Statistics/em_StatisticsPage.dart';
import 'package:flutter/material.dart';
import 'package:salomon_bottom_bar/salomon_bottom_bar.dart';

import '../Checker/DL_checkerPageVC.dart';
import '../Checker/EJ_CheckerPageVC.dart';
import '../Generator/DL_GeneratorPageVC.dart';
import '../Generator/EJ_GeneratorPageVC.dart';
import '../Home/DL_HomePageVC.dart';
import '../Home/EJ_HomePageVC.dart';
import '../Results/DL_resultsPageVC.dart';
import '../Results/EJ_ResultPageVC.dart';
import '../Statistics/DL_AnalyticsPageVC.dart';
import '../Statistics/EJ_StatisticsPageVC.dart';
import '../Statistics/KL_AnalyticsPageVC.dart';
import '../Statistics/KL_DemoPageVC.dart';
import '../tools/KaL_Config.dart';

class EJTabbarPageVC extends StatefulWidget {
  const EJTabbarPageVC({super.key});

  @override
  State<EJTabbarPageVC> createState() => _EJTabbarPageVCState();
}

class _EJTabbarPageVCState extends State<EJTabbarPageVC> {
//当前page下标
  int EJ_currentIndex = 0;
  List<SalomonBottomBarItem> EJ_tabbatItems = [];
  var EJ_pageController = PageController();
//
  late List<Widget> bottomBarViews = [
    DlHomepageVC(
      pageController: EJ_pageController,
    ),
    DL_ResultsPageVC(),
    // EJHomePageVC(
    //   pageController: EJ_pageController,
    // ),
    // EJResultPageVC(),
    // EJStatisticsPageVC(),
    // KL_AnalyticsPageVC(),
    DlAnalyticspagevc(),
    // TableDemo(),
    // StatisticsPage(),
    // EJGeneratorPageVC(),
    DlGeneratorpagevc(),
    // EJCHeckerPageVC(
    //   pageController: EJ_pageController,
    // ),
    DL_CheckerPageVC(
      pageController: EJ_pageController,
    ),
  ];

  var EJ_tabs = [
    {
      // "icon": "assets/tabIcons/home_SL.png",
      "activeIcon": "assets/icons_tabbar/tab_home.png",
      "tabName": "Home"
    },
    {
      // "icon": "assets/tabIcons/chatresult_SL.png",
      "activeIcon": "assets/icons_tabbar/tab_results.png",
      "tabName": "Results"
    },
    {
      // "icon": "assets/tabIcons/analytics_SL.png",
      "activeIcon": "assets/icons_tabbar/tab_analytics.png",
      "tabName": "Analytics"
    },
    {
      // "icon": "assets/tabIcons/genertor_SL.png",
      "activeIcon": "assets/icons_tabbar/tab_generator.png",
      "tabName": "Generator"
    },
    {
      // "icon": "assets/tabIcons/genertor_SL.png",
      "activeIcon": "assets/icons_tabbar/tab_checker.png",
      "tabName": "Checker"
    },
  ];

  getTabbarItems() {
    for (var i = 0; i < bottomBarViews.length; i++) {
      Map tab = EJ_tabs[i];
      String name = tab["tabName"];
      // String icon = tab["icon"];
      String activeIcon = tab["activeIcon"];
      EJ_tabbatItems.add(
        SalomonBottomBarItem(
          icon: Image.asset(
            activeIcon,
            width: 19,
            height: 19,
          ),
          title: Text(
            name,
            style: TextStyle(color: KaL_Config.KaL_MainColor),
          ),
          selectedColor: KaL_Config.KaL_MainColor,
        ),
      );
    }
  }

  _pageChanged(int index) {
    setState(() {
      if (EJ_currentIndex != index) EJ_currentIndex = index;
    });
  }

  _onTabTapped(int index) {
    EJ_pageController.jumpToPage(index);
  }

  @override
  void initState() {
    // TODO: implement initState
    super.initState();

    getTabbarItems();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      // body: bottomBarViews[currentIndex],
      body: PageView.builder(
          controller: EJ_pageController,
          physics: const NeverScrollableScrollPhysics(),
          onPageChanged: _pageChanged,
          itemCount: bottomBarViews.length,
          itemBuilder: (context, index) {
            return bottomBarViews[index];
          }),
      bottomNavigationBar: SalomonBottomBar(
        backgroundColor: Colors.white,
        currentIndex: EJ_currentIndex,
        onTap: (i) => setState(() {
          EJ_currentIndex = i;
          _onTabTapped(i);
        }),
        items: EJ_tabbatItems,
      ),
    );
  }
}
